package com.kx.game.center.api.response;

import com.kx.game.center.api.IGameCenterResponse;

public abstract class AbstractResponse implements IGameCenterResponse {

	private boolean success;
	private int errorCode;
	private long costTime;

	public void parseResponse(String response) {
		String[] params = response.split(":");
		if (params.length < 1) {
			this.errorCode = -1;
			this.success = false;
			return;
		}

		String status = params[0];
		if (status.equals("ok")) {
			this.success = true;
			parseReponse(params);
			return;
		}

		if (params.length < 2) {
			this.success = false;
			this.errorCode = -2;
			return;
		}

		this.success = false;
		this.errorCode = Integer.parseInt(params[1]);
	}

	public abstract void parseReponse(String[] params);

	@Override
	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public boolean isSuccess() {
		return this.success;
	}

	@Override
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	@Override
	public int getErrorCode() {
		return errorCode;
	}

	@Override
	public long getCostTime() {
		return costTime;
	}

	@Override
	public void setCostTime(long time) {
		this.costTime = time;
	}
}
